package com.acme.logging;

import java.text.SimpleDateFormat;
import java.util.Date;

class LogFormatter {

    private String pattern;

    LogFormatter(String pattern) {
        this.pattern = pattern;
    }

    String format(String loggerName, MyLogger.Level logLevel, String log) {
        String ret = pattern;
        ret = ret.replace("%d", currentTime());
        ret = ret.replace("%l", loggerName);
        ret = ret.replace("%p", logLevel.toString());
        ret = ret.replace("%t", Thread.currentThread().getName());
        ret = ret.replace("%m", log);
        return ret;
    }

    private String currentTime() {
        return new SimpleDateFormat("yyyyMMdd HH:mm:ss.SSSS").format(new Date());
    }

}
